﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InformaticaDiary.Common;

namespace InformaticaDiary.WebServiceConsumer
{
    public interface IDataAccess
    {
        ExecutedResult Delete(long Id);
        CaseDetails Fetch(long Id);
        long Maxid(string strprint);
        long Maxid1();
        long Maxid2();
        ExecutedResult Insert(long Id, CaseDetails objCD);
        ExecutedResult Update(long Id, CaseDetails objCD);
        ExecutedResult Login(LoginRequest objLoginRequest);
    }
   public class InformaticaSvcAPI : IDataAccess
    {
        CallWebService objCallSVC = new CallWebService();
        string UrlService = "http://localhost:30674/Service/InformaticaService.svc";
        public ExecutedResult Delete(long Id)
        {
            throw new NotImplementedException();
        }

        public CaseDetails Fetch(long Id)
        {
            throw new NotImplementedException();
        }

        public long Maxid(string strprint)
        {
            throw new NotImplementedException();
        }

        public long Maxid1()
        {
            throw new NotImplementedException();
        }

        public long Maxid2()
        {
            throw new NotImplementedException();
        }

        public ExecutedResult Insert(long Id, CaseDetails objCD)
        {
            throw new NotImplementedException();
        }

        public ExecutedResult Update(long Id, CaseDetails objCD)
        {
            throw new NotImplementedException();
        }

        public ExecutedResult Login(LoginRequest objLoginRequest)
        {
            string jsonString = SerializeToJson<LoginRequest>(objLoginRequest);
            string retunJson = objCallSVC.CallServicePOST(UrlService, "/Login", jsonString);
            return DeserializeFromJson<ExecutedResult>(retunJson);
        }

        public string SerializeToJson<T>(T s)
        {
            return  Newtonsoft.Json.JsonConvert.SerializeObject(s);
            
        }
        public T DeserializeFromJson<T>(string value)
        {
            return  Newtonsoft.Json.JsonConvert.DeserializeObject<T>(value);;
        }       
    }
}
